using admin.core.Entities;
using System;

namespace admin.core.Entities.App;

public class AppImage : EntityBase
{
    public string FileName { get; set; } = null!;
    public string OriginalFileName { get; set; } = null!;
    public string FilePath { get; set; } = null!;
    public string FileExtension { get; set; } = null!;
    public long FileSize { get; set; }
    public string ContentType { get; set; } = null!;
    public string? Tags { get; set; }
    public string Url { get; set; }
    public DateTime UploadTime { get; set; }
    public string? Description { get; set; }
    
    // 关联用户
    public Guid UserId { get; set; }
    public AppUser? User { get; set; }

    // 业务方法
    public bool IsImageFile()
    {
        var imageExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" };
        return imageExtensions.Contains(FileExtension.ToLower());
    }

    public string GetFullPath()
    {
        return Path.Combine(FilePath, FileName);
    }

    public string GetUrlPath()
    {
        return $"/uploads/{FileName}";
    }

    public bool IsValidSize(long maxSizeInBytes = 10 * 1024 * 1024) // 默认10MB
    {
        return FileSize <= maxSizeInBytes;
    }
} 